﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class EnemyCreater : MonoBehaviour
{
    public static EnemyCreater instance;
    private void Awake()
    {
        instance = this;
    }

    private GameObject monsterPrefab;
    private float nextTime = 0;
    public float interval = 2;
    private Transform path;
    [HideInInspector]
    public List<Transform> monsterList;
    private void Start()
    {
        monsterList = new List<Transform>();
        path = GameObject.Find("Path").transform;
        monsterPrefab = Resources.Load<GameObject>("CubeMonster");
        Debug.Log(monsterPrefab);
    }

    private void Update()
    {
        if (Time.time > nextTime)
        {
            //生成Monster
            GameObject monster = Instantiate(monsterPrefab, transform.position, Quaternion.identity);
            //指定路径
            monster.GetComponent<PathMove>().path = path;

            //放到集合中
            monsterList.Add(monster.transform);
            //设置下次生成的时间
            nextTime += interval;
        }
    }
}